package com.custom.contants;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author wh
 * @Description
 * @date 2018/4/4 16:00
 */
@Component
public class Constants {
    public static List<String> tables = new LinkedList<String>();

    public static ConcurrentHashMap<Object, ConcurrentHashMap<Object, Object>> mateMaps = new ConcurrentHashMap<Object, ConcurrentHashMap<Object, Object>>();

    public static AtomicLong initTimeStamp = new AtomicLong(0);

    public static AtomicLong updateDBMateTimeStamp = new AtomicLong(0);

    public static ConcurrentHashMap<Object, LinkedList<String>> primaryKeys = new ConcurrentHashMap<Object, LinkedList<String>>();

    public static AtomicInteger poolSize = new AtomicInteger(10);

    public static AtomicInteger initPoolSize = new AtomicInteger(3);

    @Value("#{properties.poolSize}")
    private void setPoolSize(String poolSize) {
        Constants.poolSize = new AtomicInteger(Integer.parseInt(poolSize));
    }

    @Value("#{properties.initPoolSize}")
    private void setInitPoolSize(String initPoolSize) {
        Constants.initPoolSize = new AtomicInteger(Integer.parseInt(initPoolSize));
    }

    @Value("#{properties.updateDataBaseMateTimeStamp}")
    private void setUpdateDBMateTimeStamp(String updateDBMateTimeStamp) {
        Constants.updateDBMateTimeStamp = new AtomicLong(Long.parseLong(updateDBMateTimeStamp));
    }
}
